/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package my.algorithms.mcorrea;

/**
 *
 * @author mcorrea
 */
public class CompressString {
	
	
	public static void main(String args[]){
		String str = "aaabbcccaadeeeeeeee";
		
		String compress = "";
		int count = 1 ;
		char previous = str.charAt(0);
		
		for(int k=1; k<str.length(); k++){
			
			if( str.charAt(k) == previous   ){
				count++;
			}else{
				if(count>1)
					compress +=previous+""+count;
				else 
					compress +=previous;
				
				count =1;
			}
			previous = str.charAt(k);
			
			if( k ==str.length()-1 ){
				if(count>1)
					compress +=previous+""+count;
				else 
					compress +=previous;
			}
			
		}
		
		System.out.println(str);
		System.out.println(compress);
	
	
	}
	
}
